<?php
namespace app\stores\model\promotion;

use app\common\model\CommonModel;

use think\facade\Db;

class PromotionrecordModel extends CommonModel{
    protected  $name = 'promotion_record';
    protected  $pk   = 'id';
    public static function info($where){
        $info= Db::name('promotion_record')->where($where)->find();
        return $info;
    }
    public static function list($where,$order,$page=1,$limit=10,$field='*'){
        $query = Db::name('promotion_member')
            ->where(['is_delete'=>0])
            ->when(!empty($where['is_effect']),function ($query) use ($where){
                $query->where(['is_effect'=>$where['is_effect']]);
            })
            ->when(isset($where['name']) && !empty($where['name']),function ($query) use ($where){
                $query->where('name','like','%'.$where['name'].'%');
            })
            ->field($field);
        $count = $query->count();
        $list=$query->order($order)
            ->limit($limit)->page($page)
            ->select()
            ->toArray();
        if(!empty($list)){
            foreach ($list as &$v){
            }
        }
        return compact('count','list');
    }
    public static function up($data,$where){
        $data['edit_time']=date('Y-m-d H:i:s');
        $res=self::update($data,$where);
        return $res;
    }
}
